<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <h1>刘乾坤的酒店管理系统</h1>

        <el-dropdown placement="bottom-end">
          <div>
            <el-avatar src="" />
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item @click="changeInfo">修改信息</el-dropdown-item>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-menu-item index="1" @click="router.push('/')">
              <template #title>
                <el-icon><location /></el-icon>
                <span>主页信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="2" @click="router.push('/about')">
              <el-icon><icon-menu /></el-icon>
              <span>员工信息</span>
            </el-menu-item>
            <el-menu-item index="3" @click="router.push('/reserve')">
              <el-icon><icon-menu /></el-icon>
              <span>预定订单</span>
            </el-menu-item>
            <el-menu-item index="4" @click="router.push('/Orderform')">
              <el-icon><icon-menu /></el-icon>
              <span>房间订单</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router' // 导入 useRouter 钩子函数
import { ElMessage } from 'element-plus'
// import { useIndexStore } from '../store/index'
import { reactive, ref } from 'vue'

const router = useRouter() // 调用 useRouter 钩子函数

const handleOpen = (key, keyPath) => {
  console.log(`${key} is opened`)
}

const handleClose = (key, keyPath) => {}

// 退出登录
const logout = () => {
  localStorage.removeItem('token')
  //提示信息
  ElMessage.info('请重新登录')
  router.push('/login') // 跳转到登录页面
}
//修改信息跳转
const changeInfo = () => {
  router.push('/geUser') // 跳转到登录页面
}
</script>

<style lang="scss" scoped>
.common-layout {
  background-color: #e0e0e0;
  height: 100%;
  .el-header {
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #dcdcdc;
  }
  .el-container {
    height: 100%;
    .el-aside {
      .el-menu {
        height: 100%;
      }
    }
  }
}
</style>
